package com.bishe.demo.modules.hotel.common.service.impl;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.hotel.common.dao.HotelImageDao;
import com.bishe.demo.modules.hotel.common.entity.HotelImage;
import com.bishe.demo.modules.hotel.common.service.HotelImageService;
import com.bishe.demo.modules.hotel.hotelDetail.dao.DetailHotelImageDao;
import com.bishe.demo.modules.hotel.hotelFacilityAndService.dao.FacilityHotelImageDao;
import com.bishe.demo.modules.hotel.hotelRoom.dao.RoomHotelImageDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class HotelImageServiceImpl implements HotelImageService {
    @Autowired
    private HotelImageDao imageDao;

    @Autowired
    private DetailHotelImageDao detailHotelImageDao;

    @Autowired
    private RoomHotelImageDao roomHotelImageDao;

    @Autowired
    private FacilityHotelImageDao facilityHotelImageDao;

    @Override
    @Transactional
    public ResultEntity<HotelImage> insertImage(HotelImage image) {
        imageDao.insertImage(image);
        return new ResultEntity<HotelImage>(ResultEntity.ResultStatus.SUCCESS.code, "添加图片成功", image);
    }

    @Override
    @Transactional
    public ResultEntity<HotelImage> updateImage(HotelImage image) {
        imageDao.updateImage(image);
        return new ResultEntity<HotelImage>(ResultEntity.ResultStatus.SUCCESS.code, "修改图片成功", image);
    }

    @Override
    @Transactional
    public ResultEntity<HotelImage> deleteImageByImageId(int imageId) {
        imageDao.deleteImageByImageId(imageId);
        detailHotelImageDao.deleteDetailImageByImageId(imageId);
        roomHotelImageDao.deleteRoomImageByImageId(imageId);
        facilityHotelImageDao.deleteFacilityImageByImageId(imageId);
        return new ResultEntity<HotelImage>(ResultEntity.ResultStatus.SUCCESS.code, "删除图片成功");
    }

    @Override
    public List<HotelImage> getAllImages() {
        return imageDao.getAllImages();
    }
}
